package com.bio.dao.basicinfo.impl;

import org.hibernate.criterion.Restrictions;
import com.bio.dao.basicinfo.BasicinfoDao;
import com.bio.dao.impl.HibernateDaoImpl;
import com.bio.dao.impl.HibernateQuery;
import com.bio.entity.basicinfo.Basicinfo;
import com.bio.utils.Pager;
import com.bio.utils.Pagination;

public class BasicinfoDaoImpl extends HibernateDaoImpl<Basicinfo> implements BasicinfoDao{

	@Override
	public Pager<Basicinfo> findPagerByCompanyId(Pagination pagination,
			Long companyId) {
		if(null == companyId){
			return new HibernateQuery<Basicinfo>(this.getSessionFactory(), 
				this.getSession(), Basicinfo.class).setPagination(pagination)
					                              .addWhere(Restrictions.isNull("companyId")).query();
		}else{
		    return new HibernateQuery<Basicinfo>(this.getSessionFactory(), 
				this.getSession(), Basicinfo.class).setPagination(pagination)
				                                  .addWhere(Restrictions.eq("companyId",companyId)).query();
		}
	}

	@Override
	public Pager<Basicinfo> findPagerByType(Pagination pagination, Integer type,
			Long companyId) {
		if(null == type && null == companyId){
			return new HibernateQuery<Basicinfo>(this.getSessionFactory(), 
					this.getSession(), Basicinfo.class).setPagination(pagination)
						                              .addWhere(Restrictions.isNull("companyId")).query();
		}else if(null == type && null != companyId){
			return new HibernateQuery<Basicinfo>(this.getSessionFactory(), 
					this.getSession(), Basicinfo.class).setPagination(pagination)
					                                  .addWhere(Restrictions.eq("companyId",companyId)).query();
		}else if(null != type && null == companyId){
			return new HibernateQuery<Basicinfo>(this.getSessionFactory(), 
					this.getSession(), Basicinfo.class).setPagination(pagination)
					                                   .addWhere(Restrictions.eq("type",type))	                              
					                                   .addWhere(Restrictions.isNull("companyId")).query();
		}else{
			return new HibernateQuery<Basicinfo>(this.getSessionFactory(), 
					this.getSession(), Basicinfo.class).setPagination(pagination)
					                                   .addWhere(Restrictions.eq("type",type))	                              
					                                   .addWhere(Restrictions.eq("companyId",companyId)).query();
		}
	}

}
